/**
 * Created by IntelliJ IDEA.
 * User: Liu Yuhong
 * Date: 12-10-23
 * Time: 下午8:11
 * Bid page functions
 */

$(function() {
    $( ".idBidProductDetail" ).live('click', function() {
        var detailModuls = $( this ).parent().next(".bid_detail_modules");
        if(detailModuls.is(":hidden")) {
            detailModuls.slideDown();
            $( this ).addClass("up");
        } else {
            detailModuls.slideUp();
            $( this ).removeClass("up");
        }
        return false;
    });
    if($( "#bidReduction" ).length > 0) $( "#bidReduction" ).smartFloat();
});

//合计金额
var totalAmount = document.getElementsByName("total_amount");
//数量
var amountDisplay = document.getElementsByName("amount_display");
var amountPrecision = document.getElementsByName("amount_precision");
//含税单价
var hasTaxPrice = document.getElementsByName("has_tax_price");
//税率
var taxRate = document.getElementsByName("tax_rate");
//折扣率
var detailDiscount = document.getElementsByName("detail_discount");
//折后价（含税净价或者无税竞价，统一取含税净价）
var hasTaxNetPrices = document.getElementsByName("discount_net_price");
//折后金额（价税合计）
var priceTaxSums = document.getElementsByName("discount_net_sum");
function doCalPrice(obj,index,calType){
	if(obj.value == "" || obj.value == null){
		//return;
	}
	var editRow = 0;
	editRow = index - 1;
	//计算标识
	var calFlag = document.getElementsByName("cal_flag");
	calFlag[editRow].value = "0";
	//物料主健
	var prodPks = document.getElementsByName("pk_prod_v");
	document.calpriceform.pk_prod_cal.value = prodPks[editRow].value;
	//报价单位
	var prodUnitPks = document.getElementsByName("pk_prod_unit");
	document.calpriceform.pk_unit_cal.value = prodUnitPks[editRow].value;
	//数量
	var amounts = document.getElementsByName("amount");  
	document.calpriceform.amount_cal.value = amounts[editRow].value;
	//含税单价
	var hasTaxPrices = document.getElementsByName("has_tax_price");
	//折后金额（价税合计）
	var discountNetSum = document.getElementsByName("discount_net_sum");
	if((hasTaxPrices[editRow].value == "" || hasTaxPrices[editRow].value == null)
		&& (discountNetSum[editRow].value == "" || discountNetSum[editRow].value == null)){
		hasTaxPrices[editRow].value == "0.00";
	}
	document.calpriceform.has_tax_price_cal.value = hasTaxPrices[editRow].value;
	document.calpriceform.price_tax_sum_cal.value = discountNetSum[editRow].value;
	//税率
	var taxRates = document.getElementsByName("tax_rate");
	if(taxRates[editRow].value == "" || taxRates[editRow].value == null){
		taxRates[editRow].value = "0.00";
	}
	document.calpriceform.tax_rate_cal.value = taxRates[editRow].value;
	//折扣率
	var discountRates = document.getElementsByName("detail_discount");
	if(discountRates[editRow].value == "" || discountRates[editRow].value == null){
		return;
	}
	document.calpriceform.discount_rate_cal.value = discountRates[editRow].value;
	//行号
	document.calpriceform.row_no.value = index - 1;
	//计算字段
	if(hasTaxPrices[editRow].value != "" && hasTaxPrices[editRow].value != null && hasTaxPrices[editRow].value != "null" && calType == 1){
		document.calpriceform.property_cal.value = "has_tax_price";
		document.calpriceform.changUnitPrice.value = "false";
	}else{
		document.calpriceform.property_cal.value = "price_tax_sum";
		document.calpriceform.changUnitPrice.value = "true";
	}
	//提交表单
	var formStr = $('#calpriceform').serialize();
	$.ajax( {
		url : ebvpContext+"/sourcing/biddingprojlist/calprice",
		type : "POST",
		data : "&" + formStr,
		dataType : "text",
		async : true,
		success : function(responseText) {
			showResponse(responseText);
		}
	});
}

function showResponse(responseText, statusText, xhr, $form) {
	// 0:报价数量|1:税率|2:折扣率|3:含税单价|4:价税合计（含税金额）|5:含税净价|6:主含税净价|7:无税单价|8:无税金额|9:无税净价|10:主无税净价|11:税e|12:行号
	var responseArr = responseText.split("|");
	//计算标识
	var calFlag = document.getElementsByName("cal_flag");
	//数量
	var amounts = document.getElementsByName("amount");  
	//含税单价
	var hasTaxPrices = document.getElementsByName("has_tax_price");
	hasTaxPrices[responseArr[12]].value = subRedubqNum(responseArr[3],intPricePrecision);
	//税率
	var taxRates = document.getElementsByName("tax_rate");
	taxRates[responseArr[12]].value = subRedubqNum(responseArr[1],2);
	//折扣率
	var discountRates = document.getElementsByName("detail_discount");
	discountRates[responseArr[12]].value = subRedubqNum(responseArr[2],2);
	//折后价（含税净价或者无税竞价，统一取含税净价）
	var hasTaxNetPrices = document.getElementsByName("discount_net_price");
	hasTaxNetPrices[responseArr[12]].value = subRedubqNum(responseArr[5],intPricePrecision);
	//折后金额（价税合计）
	var priceTaxSums = document.getElementsByName("discount_net_sum");
	priceTaxSums[responseArr[12]].value = subRedubqNum(responseArr[4],intMnyPrecision);
	//更新报价单元合计数据
	var isProdItem = document.getElementsByName("is_prod_item");
	var totalAmount = document.getElementsByName("total_amount");
	var prodTotalAmount = document.getElementsByName("prod_total_amount");
	var lastTotalAmount = document.getElementsByName("last_total_amount");
	var prodTotalAmountValue = null;
	var lastTotalAmountValue = 0;
	for(var i=0;i<isProdItem.length;i++){
		if(isProdItem[i].value == "Y"){
			totalAmount[i].value = "0.00";
			for(var j=0;j<priceTaxSums.length;j++){
				if(parseFloat(amounts[j].value) > 0){
					//数量不为空的情况，则累加金额
					if(priceTaxSums[j].value != "" && priceTaxSums[j].value != null && priceTaxSums[j].value != "null"){
						totalAmount[i].value = parseFloat(totalAmount[i].value) + parseFloat(priceTaxSums[j].value);
					}
				}else{
					//数量为空时，则累加折后含税单价
					if(hasTaxNetPrices[j].value != "" && hasTaxNetPrices[j].value != null && hasTaxNetPrices[j].value != "null"){
						totalAmount[i].value = parseFloat(totalAmount[i].value) + parseFloat(hasTaxNetPrices[j].value);
					}
				}
			}
			subReduNum(totalAmount[i],intMnyPrecision);
			prodTotalAmountValue = totalAmount[i].value;
		}
		if(totalAmount[i].value != "" && totalAmount[i].value != null && totalAmount[i].value != "null"){
			lastTotalAmountValue = lastTotalAmountValue + parseFloat(totalAmount[i].value);
		}
	}
	prodTotalAmount[0].value = prodTotalAmountValue;
	lastTotalAmount[0].value = lastTotalAmountValue;
	subReduNum(lastTotalAmount[0],intMnyPrecision);
	//设置降价幅度信息
	setReduInfo(lastTotalAmountValue,intMnyPrecision);
	//计算标识
	calFlag[responseArr[12]].value = "1";
}

function doCalLastTotalAmount() {
	//更新报价单元合计数据
	var totalAmount = document.getElementsByName("total_amount");
	var lastTotalAmount = document.getElementsByName("last_total_amount");
	var lastTotalAmountValue = 0;
	for(var i=0;i<totalAmount.length;i++){
		if(totalAmount[i].value != "" && totalAmount[i].value != null && totalAmount[i].value != "null"){
			lastTotalAmountValue = lastTotalAmountValue + parseFloat(totalAmount[i].value);
		}
	}
	lastTotalAmount[0].value = lastTotalAmountValue;
	subReduNum(lastTotalAmount[0],intMnyPrecision);
	//设置降价幅度信息
	setReduInfo(lastTotalAmountValue,intMnyPrecision);
}

//设置降价幅度信息
function setReduInfo(lastTotalAmountValue,intMnyPrecision){
	$( "#total_amount_redu" ).html(subRedubqNum(lastTotalAmountValue,intMnyPrecision));
	var dRedu = lastTotalAmountValue - $( "#last_total_amount_hidden" )[0].value;
	dRedu = subRedubqNum(dRedu,intMnyPrecision);
	if(dRedu < 0){
		dRedu = 0 - dRedu;
		$( "#total_redu_title" ).html(getLanMsg("0ec22214-000145"));
	}else{
		$( "#total_redu_title" ).html(getLanMsg("0ec22214-000146"));
	}
	var dReduRate;
	var lastAmountHidden = $( "#last_total_amount_hidden" )[0].value;
	if(lastAmountHidden == 0){
		dReduRate = 100;
	}else{
		dReduRate = (dRedu / $( "#last_total_amount_hidden" )[0].value) * 100;
	}
	if(dReduRate < 0){
		dReduRate = 0 - dReduRate;
	}
	dReduRate = subRedubqNum(dReduRate,intMnyPrecision);
	$( "#total_redu" ).html(dRedu+"("+dReduRate+")%");
}

function doQuote(bsubmit){
	var bResult = true;
	bResult = checkInput();
	if(bResult){
		//判断是否已经计算完毕
		var calFlag = document.getElementsByName("cal_flag");
		if(null != calFlag){
			for(var i=0;i<calFlag.length;i++){
				if("0" == calFlag[i].value){
					alert(getLanMsg("0ec22214-000103")+ (i+1) +getLanMsg("0ec22214-000079") + getLanMsg("0ec22214-000183"));
					return;
				}
			}
		}
		//签名
		if (isClientCa == "true") {
			bResult = doVerifyPriceData();
		}
		//校验供应商设置的最低总价
		bResult = checkLowPrice();
		//提交按钮置灰
		var btnSubmit = document.getElementById("bidSubmit");
		btnSubmit.href = "javascript:void(null);";
		var btnSave = document.getElementById("bidSave");
		btnSave.href = "javascript:void(null);";
		$("#data_submit").val(bsubmit);
		var formStr = $('#quoteform').serialize();
		$.ajax( {
			url : ebvpContext+"/sourcing/biddingprojlist/doquote",
			type : "POST",
			data : "&" + formStr,
			dataType : "text",
			async : true,
			success : function(responseText) {
				showResponse2(responseText);
			}
		});
	}
}

// post-submit callback 
function showResponse2(responseText, statusText, xhr, $form) {
	var strMsg1 = getLanMsg("0ec22214-000054");
	var strMsg2 = getLanMsg("0ec22214-000055");
	if(responseText.indexOf("error:") > -1){
		responseText = responseText.substring(6);
		showMsg(responseText);
		//提交按钮激活
		var btnSubmit = document.getElementById("bidSubmit");
		btnSubmit.href = "javascript:doQuote(true);";
		var btnSave = document.getElementById("bidSave");
		btnSave.href = "javascript:doQuote(false);";
		return;
	}
	var responseArr = responseText.split("|");
	var headPks = document.getElementsByName("pk_pricedata_h");
	var bodyPks = document.getElementsByName("pk_pricedata_b");
	var psn = document.getElementById("commit_psn");
	var time = document.getElementById("commit_time");
	var i = 0;
	for(i=0;i<headPks.length;i++){
		headPks[i].value = responseArr[i];
	}
	if(responseArr.length > i){
		for(j=0;j<bodyPks.length;j++){
			bodyPks[j].value = responseArr[i+j];
		}
	}
	//根据竞价策略设置报价默认值
	if(document.quoteform.data_submit.value == "true"){
		//resetPrice();
	}
	if($("#data_submit").val() == "true"){
		//变更提交信息
		psn.innerHTML = userName;
		time.innerHTML = responseArr[responseArr.length - 2];
		//提交成功后更新上次隐藏的上次报价总额字段
		$( "#last_total_amount_hidden" )[0].value = $( "#last_total_amount" )[0].value;
		setReduInfo($( "#last_total_amount" )[0].value,intMnyPrecision);
		showMsg(strMsg1);
	}else{
		showMsg(strMsg2);
	}
	//document.getElementById("reply_note").value = responseArr[responseArr.length - 1];
	//提交按钮激活
	var btnSubmit = document.getElementById("bidSubmit");
	btnSubmit.href = "javascript:doQuote(true);";
	var btnSave = document.getElementById("bidSave");
	btnSave.href = "javascript:doQuote(false);";
	//$( "#bidReduction" ).hide();
}

//批量修改折扣率对话框
function showUptDiscountDialog(){
	var strMsg1 = getLanMsg("0ec22214-000056");
	var strMsg2 = getLanMsg("0ec22214-000057");
	var strMsg3 = getLanMsg("0ec22214-000058");
	var strContent = "";
	strContent = strContent + "<div style='width:300px;margin-left:150px;margin-bottom:10px;'>";
	strContent = strContent + "		<span>" + strMsg1 + "  </span>";
	strContent = strContent + "		<input type='text' id='update_discount' name='update_discount' onchange='subReduNum(this,2);' onkeypress='javascript:keyPress(this,event);' value='' />";
	strContent = strContent + "</div>";
	strContent = strContent + "<div id='update_msg' name='update_msg' style='margin-left:30px;color:red'>";
	strContent = strContent + " </div>";
	seajs.use('common/dialog/src/js/dialog_ec',
		function(dialog) {
			dialog.confirm({
				type:"confirm",
				title:strMsg2,
				isHtmlContent:true,
				top:500,
				confirm:function(){
					var objDiscount = document.getElementById("update_discount");
					var strDiscount = objDiscount.value;
					if(strDiscount == null || strDiscount == ""){
						$("#update_msg").html(strMsg3);
						return;
					}
					updateDiscount(objDiscount);
					return true;
				},
				content:strContent
			});
		});
}

//批量修改折扣率
function updateDiscount(obj){			   
	var val = document.getElementById("update_discount").value;
	var objDiscount = document.getElementsByName("detail_discount");
	if(objDiscount != null){
		for(var i=0; i<objDiscount.length; i++){
			objDiscount[i].value = val;
			doCalPrice(obj,i+1,1);				
		}				
	}
}

//批量修改税率对话框
function showUptTaxrateDialog(){
	var strMsg1 = getLanMsg("0ec22214-000059");
	var strMsg2 = getLanMsg("0ec22214-000060");
	var strMsg3 = getLanMsg("0ec22214-000061");
	var strContent = "";
	strContent = strContent + "<div style='width:300px;margin-left:150px;margin-bottom:10px;'>";
	strContent = strContent + "		<span>" + strMsg1 + "  </span>";
	strContent = strContent + "		<input type='text' id='update_taxrate' name='update_taxrate' onchange='subReduNum(this,2);' onkeypress='javascript:keyPress(this,event);' value='' />";
	strContent = strContent + "</div>";
	strContent = strContent + "<div id='update_msg' name='update_msg' style='margin-left:30px;color:red'>";
	strContent = strContent + "</div>";
	seajs.use('common/dialog/src/js/dialog_ec',
		function(dialog) {
			dialog.confirm({
				type:"confirm",
				title:strMsg2,
				isHtmlContent:true,
				top:500,
				confirm:function(){
					var objTaxrate = document.getElementById("update_taxrate");
					var strTaxrate = objTaxrate.value;
					if(strTaxrate == null || strTaxrate == ""){
						$("#update_msg").html(strMsg3);
						return;
					}
					updateTaxrate();
					return true;
				},
				content:strContent
			});
		});
}

//批量修改税率
function updateTaxrate(){			   
	var val = document.getElementById("update_taxrate").value;
	var objTaxRate = document.getElementsByName("tax_rate");
	if(objTaxRate != null){
		for(var i=0; i<objTaxRate.length; i++){
			objTaxRate[i].value = val;			
		}				
	}
}

//设置降价策略
function showUptPolicyDialog(){
	var strMsg1 = getLanMsg("0ec22214-000062");
	var strMsg2 = getLanMsg("0ec22214-000063");
	var strMsg3 = getLanMsg("0ec22214-000064");
	var strMsg4 = getLanMsg("0ec22214-000065");
	var strMsg5 = getLanMsg("0ec22214-000066");
	var strMsg6 = getLanMsg("0ec22214-000067");
	var strMsg7 = getLanMsg("0ec22214-000068");
	var strMsg8 = getLanMsg("0ec22214-000069");
	var strMsg9 = getLanMsg("0ec22214-000070");
	var strMsg10 = getLanMsg("0ec22214-000071");
	var strMsg11 = getLanMsg("0ec22214-000072");
	var strMsg12 = getLanMsg("0ec22214-000073");
	if("N" == strPriceDown){
		strMsg1 = getLanMsg("0ec22214-000150");
		strMsg2 = getLanMsg("0ec22214-000151");
		strMsg3 = getLanMsg("0ec22214-000152");
		strMsg4 = getLanMsg("0ec22214-000153");
		strMsg5 = getLanMsg("0ec22214-000154");
		strMsg6 = getLanMsg("0ec22214-000155");
		strMsg7 = getLanMsg("0ec22214-000156");
		strMsg8 = getLanMsg("0ec22214-000157");
		strMsg9 = getLanMsg("0ec22214-000158");
		strMsg10 = getLanMsg("0ec22214-000159");
		strMsg11 = getLanMsg("0ec22214-000160");
		strMsg12 = getLanMsg("0ec22214-000161");
	}
	var strContent = "";
	strContent = strContent + "<div style='width:400px;margin-left:30px;margin-bottom:10px;'>";
	strContent = strContent + "<span>" + strMsg1 + "  </span>";
	strContent = strContent + "</div>";
	strContent = strContent + "<div style='width:300px;margin-left:30px;margin-bottom:10px;'>";
	strContent = strContent + "<span>" + strMsg2 + " </span><input type='text' id='down_percent' name='down_percent' style='width:60px' onchange='subReduNum(this,2);' onkeypress='javascript:keyPress(this,event);' value='' />";
	strContent = strContent + "<span>% " + strMsg3 + " </span><input type='text' id='down_price' name='down_price' style='width:60px' onchange='subReduNum(this,"+intPricePrecision+");' onkeypress='javascript:keyPress(this,event);' value='' />";
	strContent = strContent + "</div>";
	strContent = strContent + "<div style='width:400px;margin-left:30px;margin-bottom:10px;'>";
	strContent = strContent + "<span>" + strMsg4 + "</span>";
	strContent = strContent + "</div>";
	strContent = strContent + "<div style='width:300px;margin-left:30px;margin-bottom:10px;'>";
	strContent = strContent + "<span>" + strMsg5 + " </span><input type='text' id='down_percent_mny' name='down_percent_mny' style='width:60px' onchange='subReduNum(this,2);' onkeypress='javascript:keyPress(this,event);' value='' />";
	strContent = strContent + "<span>% " + strMsg3 + "</span><input type='text' id='down_price_mny' name='down_price_mny' style='width:60px' onchange='subReduNum(this,"+intMnyPrecision+");' onkeypress='javascript:keyPress(this,event);' value='' />";
	strContent = strContent + "</div>";
	strContent = strContent + "<div style='width:400px;margin-left:30px;margin-bottom:10px;'>";
	strContent = strContent + "<span>" + strMsg6 + "</span>";
	strContent = strContent + "</div>";
	strContent = strContent + "<div style='width:300px;margin-left:30px;margin-bottom:10px;'>";
	strContent = strContent + "<span>" + strMsg7 + " </span>";
	strContent = strContent + "<input type='text' id='low_price' name='low_price' style='width:60px' onchange='subReduNum(this,"+intMnyPrecision+");' onkeypress='javascript:keyPress(this,event);' value='' />";
	strContent = strContent + "</div>";
	strContent = strContent + "<div id='update_msg' name='update_msg' style='margin-left:30px;color:red'></div>";
	seajs.use('common/dialog/src/js/dialog_ec',
		function(dialog) {
			dialog.confirm({
				type:"confirm",
				title:strMsg8,
				isHtmlContent:true,
				top:500,
				confirm:function(){
					var isMnyDown = "N";
					var downPercent = document.getElementsByName("down_percent")[1].value;
					var downPrice = document.getElementsByName("down_price")[1].value;
					var downPercentMny = document.getElementsByName("down_percent_mny")[1].value;
					var downPriceMny = document.getElementsByName("down_price_mny")[1].value;
					var lowPrice = document.getElementsByName("low_price")[1].value;
					if(trim(downPercent) == "" && trim(downPrice) == "" 
						&& trim(downPercentMny) == "" && trim(downPriceMny) == ""){
						$("#update_msg").html(strMsg9);
						return;
					}
					if((trim(downPercent) != "" || trim(downPrice) != "") 
						&& (trim(downPercentMny) != "" || trim(downPriceMny) != "")){
						$("#update_msg").html(strMsg10);
						return;
					}
					if((trim(downPercent) != "" && trim(downPrice) != "")
						|| (trim(downPercentMny) != "" && trim(downPriceMny) != "")){
						$("#update_msg").html(strMsg11);
						return;
					}
					if(trim(lowPrice) == ""){
						$("#update_msg").html(strMsg12);
						return;
					}
					if(trim(downPercentMny) != "" || trim(downPriceMny) != ""){
						isMnyDown = "Y";
					}
					updatePolicy(isMnyDown,downPercent,downPrice,downPercentMny,downPriceMny,lowPrice);
					return true;
				},
				content:strContent
			});
		});
}

function updatePolicy(isMnyDown,downPercent,downPrice,downPercentMny,downPriceMny,lowPrice){
	document.quoteform.is_mny_down.value = isMnyDown;
	document.quoteform.down_percent.value = downPercent;
	document.quoteform.down_price.value = downPrice;
	document.quoteform.down_percent_mny.value = downPercentMny;
	document.quoteform.down_price_mny.value = downPriceMny;
	document.quoteform.low_price.value = lowPrice;
	var formStr = $('#quoteform').serialize();
	$.ajax( {
		url : ebvpContext+"/sourcing/biddingprojlist/quotepolicy",
		type : "POST",
		data : "&" + formStr,
		dataType : "text",
		async : false,
		success : function(responseText) {
			//showResponse2(responseText);
			resetPrice();
		}
	});
}

//校验必输项
function checkInput(){
	var strMsg1 = getLanMsg("0ec22214-000074");
	var strMsg2 = getLanMsg("0ec22214-000075");
	var strMsg3 = getLanMsg("0ec22214-000076");
	var strMsg4 = getLanMsg("0ec22214-000077");
	var strMsg5 = getLanMsg("0ec22214-000078");
	var strMsg6 = getLanMsg("0ec22214-000079");
	var strMsg7 = getLanMsg("0ec22214-000080");
	var strMsg8 = getLanMsg("0ec22214-000081");
	var strMsg9 = getLanMsg("0ec22214-000082");
	//var strMsg10 = getLanMsg("0ec22214-000083");
	var strMsg11 = getLanMsg("0ec22214-000084");
	var bResult = true;
	var nullMsg = "";
	var digitMsg = "";
	var cellItems = new Array();
	cellItems[0] = hasTaxPrice;
	cellItems[1] = taxRate;
	cellItems[2] = detailDiscount;
	var cellNames = new Array();
	cellNames[0] = strMsg1;
	cellNames[1] = strMsg2;
	cellNames[2] = strMsg3;
	//数量
	var fieldValue;
	//是否有产品明细行已报价
	var bIsQuoted = false;
	if("Y" == isPartPrice){
		var count = 0;
		for(var i=0;i<hasTaxPrice.length;i++){
			if("" !=cellItems[0][i].value && !isNaN(cellItems[0][i].value)){
				count++;
			}
		}
		if(count == 0 && hasTaxPrice.length>0){
			showMsg(strMsg4);
			return false;
		}
	}
	//检查报价明细的含税单价、税率、折扣率
	for(var i=0;i<hasTaxPrice.length;i++){
		for(var j=0;j<cellItems.length;j++){
			cellItems[j][i].value = trim(cellItems[j][i].value);
			fieldValue = cellItems[j][i].value;
			if(fieldValue == ""){
				if(null != nullMsg){
					nullMsg = nullMsg + "\r\n";
				}
				nullMsg = nullMsg + strMsg5 + (i+1) + strMsg6 + cellNames[j] + strMsg7;
			}else {
				bIsQuoted = true;
				if(isNaN(fieldValue)){
					if(null != digitMsg){
						digitMsg = digitMsg + "\r\n";
					}
					digitMsg = digitMsg + strMsg5 + (i+1) + strMsg6 + cellNames[j] + strMsg8;
				}
			}
		}
	}
	//如果允许部分报价，且有部分产品报价，则不提示未输入报错信息
	if(isPartPrice == "Y" && bIsQuoted){
		nullMsg = "";
	}
	//检查报价单元的合计金额
	for(var i=0;i<totalAmount.length;i++){
		totalAmount[i].value = trim(totalAmount[i].value);
		fieldValue = totalAmount[i].value;
		if(fieldValue == ""){
			if(null != nullMsg){
				nullMsg = nullMsg + "\r\n";
			}
			nullMsg = nullMsg + strMsg9 + (i+1);
		}else if(isNaN(fieldValue)){
			if(null != digitMsg){
				digitMsg = digitMsg + "\r\n";
			}
			digitMsg = digitMsg + strMsg11 + (i+1);
		}
	}
	if(nullMsg != ""){
		showMsg(nullMsg);
		bResult = false;
	}
	if(digitMsg != ""){
		showMsg(digitMsg);
		bResult = false;
	}
	return bResult;
}

//根据竞价策略设置报价默认值
function resetPrice(){
	var isMnyDown = document.quoteform.is_mny_down.value;
	var downPercent = document.quoteform.down_percent.value;
	var downPrice = document.quoteform.down_price.value;
	var downPercentMny = document.quoteform.down_percent_mny.value;
	var downPriceMny = document.quoteform.down_price_mny.value;
	var hasTaxPrice = document.getElementsByName("has_tax_price");
	var hasTaxMny = document.getElementsByName("discount_net_sum");
	if(isMnyDown == "N"){
		if(null != downPercent && "" != downPercent){
			for(i=0;i<hasTaxPrice.length;i++){
				if("Y" == strPriceDown){
					hasTaxPrice[i].value = parseFloat(hasTaxPrice[i].value) - parseFloat(hasTaxPrice[i].value)/100*parseFloat(downPercent);
				}else{
					hasTaxPrice[i].value = parseFloat(hasTaxPrice[i].value) + parseFloat(hasTaxPrice[i].value)/100*parseFloat(downPercent);
				}
				if(hasTaxPrice[i].value.indexOf("-") > -1){
					hasTaxPrice[i].value = "0.00";
				}
				hasTaxPrice[i].onchange();
			}
		}else if(null != downPrice && "" != downPrice){
			for(i=0;i<hasTaxPrice.length;i++){
				if("Y" == strPriceDown){
					hasTaxPrice[i].value = parseFloat(hasTaxPrice[i].value) - parseFloat(downPrice);
				}else{
					hasTaxPrice[i].value = parseFloat(hasTaxPrice[i].value) + parseFloat(downPrice);
				}
				if(hasTaxPrice[i].value.indexOf("-") > -1){
					hasTaxPrice[i].value = "0.00";
				}
				hasTaxPrice[i].onchange();
			}
		}
	}else{
		if(null != downPercentMny && "" != downPercentMny){
			for(i=0;i<hasTaxMny.length;i++){
				//金额大于0时才设置降价策略
				if(parseFloat(hasTaxMny[i].value) > 0){
					if("Y" == strPriceDown){
						hasTaxMny[i].value = parseFloat(hasTaxMny[i].value) - parseFloat(hasTaxMny[i].value)/100*parseFloat(downPercentMny);
					}else{
						hasTaxMny[i].value = parseFloat(hasTaxMny[i].value) + parseFloat(hasTaxMny[i].value)/100*parseFloat(downPercentMny);
					}
					if(hasTaxMny[i].value.indexOf("-") > -1){
						hasTaxMny[i].value = "0.00";
					}
					hasTaxMny[i].onchange();
				}
			}
		}else if(null != downPriceMny && "" != downPriceMny){
			for(i=0;i<hasTaxMny.length;i++){
				//金额大于0时才设置降价策略
				if(parseFloat(hasTaxMny[i].value) > 0){
					if("Y" == strPriceDown){
						hasTaxMny[i].value = parseFloat(hasTaxMny[i].value) - parseFloat(downPriceMny);
					}else{
						hasTaxMny[i].value = parseFloat(hasTaxMny[i].value) + parseFloat(downPriceMny);
					}
					if(hasTaxMny[i].value.indexOf("-") > -1){
						hasTaxMny[i].value = "0.00";
					}
					hasTaxMny[i].onchange();
				}
			}
		}
	}
}

//校验供应商设置的最低总价
function checkLowPrice(){
	var strMsg1 = getLanMsg("0ec22214-000085");
	var strMsg2 = getLanMsg("0ec22214-000169");
	var bResult = true;
	var lowPrice = document.quoteform.low_price.value;
	if(null != lowPrice && "" != lowPrice){
		var dLowPrice = parseFloat(lowPrice);
		var dTotalPrice = document.getElementsByName("last_total_amount")[0].value;
		if("Y" == strPriceDown && dLowPrice > dTotalPrice){
			bResult = confirm(strMsg1);
		}else if("N" == strPriceDown && dLowPrice < dTotalPrice){
			bResult = confirm(strMsg2);
		}
	}
	return bResult;
}
//报价数据签名
function doVerifyPriceData(){
	//报价单元合计金额
	var totalPrice = document.getElementsByName("total_amount");
	//是否产品项
	var isProdItem = document.getElementsByName("is_prod_item");
	//产品明细报价
	//数量
	var amount = document.getElementsByName("amount");
	//含税单价
	var hasTaxPrice = document.getElementsByName("has_tax_price");
	//税率
	var taxRate = document.getElementsByName("tax_rate");
	//折扣率
	var detailDiscount = document.getElementsByName("detail_discount");
	//待签名消息串
	var strVerifyPriceData = "";
	//证书SN
	var strSn = getSN(strUserCode);
	if(strSn == null || strSn == ""){
		showMsg(getLanMsg("0ec22214-000021"));
		return false;
	}
	document.quoteform.casn.value = strSn;
	for(var i=0;i<totalPrice.length;i++){
		strVerifyPriceData = totalPrice[i].value + "|";
		if(isProdItem[i].value == "Y" && amount != null && amount != "null"){
			for(var j=0;j<amount.length;j++){
				strVerifyPriceData = strVerifyPriceData + amount[j].value + "|";
				strVerifyPriceData = strVerifyPriceData + hasTaxPrice[j].value + "|";
				strVerifyPriceData = strVerifyPriceData + taxRate[j].value + "|";
				strVerifyPriceData = strVerifyPriceData + detailDiscount[j].value + "|";
			}
		}
		//签名
		document.getElementsByName("signature")[i].value = signmessage(strVerifyPriceData,strUserCode);
	}
	return true;
}

//供应商被踢出
function kickLogout(reason){
	//var url = "<%=basePath%>/sourcingcoll/quotelogin.jsp?pkProj=${ONLINEQUOTE_FORM.pk_pur_project}"+"&pkProjStep=${ONLINEQUOTE_FORM.pk_purproj_step}";
	var url = ebvpContext;
	alert(getLanMsg("0ec22214-000086"));
	document.location.href = url;
}

//竞价须知
function getQuoteInform(){
	var title = getLanMsg("0ec22214-000022");
	var url = ebvpContext+"/sourcingcoll/quoteinform.jsp";
	var vTop = (window.screen.availHeight-30-500)/2;
	var vLeft = (window.screen.availWidth-10-420)/2;
	window.open(url,'' ,'width=500,height=420,location=no,top='+vTop+',left='+vLeft);
	//var url = "url:post?<%=basePath%>/sourcingcoll/quoteinform.jsp";
	//dialog(title, url,"500", "auto", "", "");
}
//查看报价历史
function getOldPrice(){
	var title = getLanMsg("0ec22214-000087");
	var url = ebvpContext+"/sourcing/biddingprojlist/getoldquote?projPk=${PURPROJECT_FORM.pk_pur_project}&onlineQuotePk=${ONLINEQUOTE_FORM.pk_onlinequote_h}&quoteType=${ONLINEQUOTE_FORM.quote_type}&quote_index=0";
	window.open(url,'' ,'width=1024,height=768,location=yes');
}
//导出报价
function exportPrice(){
	document.quoteform.action = ebvpContext+"/sourcing/biddingprojlist/haspricedata";
	//检查是否有报价
	var options3 = {
		beforeSubmit : showRequest3, 
		success : showResponse3
	};
	$('#quoteform').ajaxSubmit(options3);
}
function showRequest3(formData, jqForm, options) {
	//alert("formData:="+formData);
}
function showResponse3(responseText, statusText, xhr, $form) {
	if(responseText == "Y"){
		document.quoteform.action = ebvpContext+"/sourcing/biddingprojlist/doexport";
		document.quoteform.submit();
	}else{
		showMsg(getLanMsg("0ec22214-000088"));
	}
}
//设置降价策略
function setQuoteRule(){
	var downPercent = document.quoteform.down_percent.value;
	var downPrice = document.quoteform.down_price.value;
	var downPercentMny = document.quoteform.down_percent_mny.value;
	var downPriceMny = document.quoteform.down_price_mny.value;
	var lowPrice = document.quoteform.low_price.value;
	var title = getLanMsg("0ec22214-000089");
	var url = ebvpContext+"/sourcingcoll/quotepolicy.jsp?onlineQuotePk=${ONLINEQUOTE_FORM.pk_onlinequote_h}&downPercent="+downPercent+"&downPrice="+downPrice+"&downPercentMny="+downPercentMny+"&downPriceMny="+downPriceMny+"&lowPrice="+lowPrice+"&mnyPrecision=${MONEY_PRECISION}&pricePrecision=${PRICE_PRECISION}";
	window.open(url,'' ,'width=1024,height=768,location=no');
}

//隐藏竞价须知
function hideInform(isHide){
	if(isHide){
		$(".detail").hide();
	}else{
		$(".detail").show();
	}
}
//提交响应信息
var showMsg = function(msg){
	document.getElementById('show_msg').innerHTML = msg;
}